<?php
class Catalog_IndexController extends Zend_Controller_Action
{
public $filters=array('search'=>array('HtmlEntities','StripTags','StringTrim','Alnum'),'page'=>array('HtmlEntities','StripTags','StringTrim'));
public $validators=array('search'=>array(),'page'=>'Int');
	public function preDispatch()
	{
	
	}
	public function init()
	{

	}

	public function indexAction()
	{

	}
	public function searchAction()
	{
        if($this->getRequest()->isPost()){
        $input=new Zend_Filter_Input($this->filters,$this->validators);
        $input->setData($this->getRequest()->getParams());
            if($input->isValid() ){
            $data=$this->getRequest()->getPost();
                if(!empty($data['search'])){
                Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
                Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('UTF-8');
                $config=$this->getInvokeArg('bootstrap')->getOption('indexes');
                $index=Zend_Search_Lucene::open($config['indexPath']);
                $results=$index->find(Zend_Search_Lucene_Search_QueryParser::parse($data['search']));
                $this->view->results=$results;

                }
            }
        }
    }
    public function feedAction(){

        $art = new Myblog_Model_Articles();
        $lastArt= $art->getLastArticles();
        if(count($lastArt)){

            $title = 'ITdocs.kz';
            $urlPrefix = 'http://itdocs.kz';
            $link = $urlPrefix;
            $description = 'ITdocs.kz новости и статьи на it-тематику';
            $charset = 'UTF-8';

            $feedArray = array(
                'title'       => $title,
                'link'        => $link,
                'description' => $description,
                'charset'     => $charset,
                'entries'     => array()
            );
            foreach($lastArt as $i){

                $date = new Zend_Date($i['created_dt'],'YYYY-MM-dd HH:mm:ss');
                $timestp = $date->getTimestamp();

                $feedArray['entries'][] = array(
                    'title'       => $i['title'],
                    'link'        => $urlPrefix . '/' . $i['category_name'] . '/' . $i['article_id'],
                    'description' => $i['description'],
                    'lastUpdate'  => $timestp
                );

            }
            $this->_helper->getHelper('layout')->disableLayout();

            $feed = Zend_Feed::importArray($feedArray, 'rss');
            $feed->send();

        }

    }
}
	
